<style>
  #memberMain .tapList .tableClassA tbody tr {
    height: 32px;
    line-height: 32px;
  }

  #memberMain .tapList .tableClassA tbody tr td {
    padding: 0;
  }
</style>
<div id="memberMain" class="success">
  <div class="title"><h4>积分提现</h4></div>
  <div class="tipsTop">原始积分提取收取20%产品手续费</div>
  <div class="height18"></div>
  <form autocomplete="off" id="recharge-form">
    <ul class="formUl" id="userBank">
      <li class="">
        <label class="inputName">会员编号</label>
        <input class="inputText cardName" name="username" value="" id="username" type="text"
               style="color: rgb(0, 0, 0);" disabled="">
      </li>
      <li class="">
        <label class="inputName">交易平台</label>
        <select name="style" id="to">
          <option value="0">选择转入的交易平台</option>
          <option value="yunshu">币九区</option>
        </select>
        <div class="errorMessage">如果你还未绑定交易平台请
          <a ui-sref="transaction.buy.bind">点击此处</a>
        </div>
      </li>
      <li class="">
        <label class="inputName">积分类型</label>
        <select name="pointType" id="pointType" onchange="tipsTop(this)">
          <option value="original">原始积分(0.00)</option>
          <!--<option value="repeat">复投积分(0.00)</option>-->
          <option value="static">静态积分(0.00)</option>
          <option value="dynamic">动态积分(0.00)</option>
        </select>
      </li>
      <li class="">
        <label class="inputName">提取积分</label>
        <input class="inputText" maxlength="32" name="money" id="pointAmount" type="text"
               style="color: rgb(0, 0, 0);" onchange="calculatePoint()">
        <div class="errorMessage">久福币价格
          <span id="coinPrice"></span>
        </div>
      </li>
      <li class="">
        <label class="inputName">久福币</label>
        <input class="inputText" maxlength="32" value="0.00" name="score" id="coinAmount" type="text"
               style="color: rgb(0, 0, 0);" disabled="">
        <div class="errorMessage" id="errorMessage">(提取积分-复消积分-公益积分)/当前久福币价格</div>
      </li>
      <li class="">
        <label class="inputName">交易密码</label>
        <input class="inputText" maxlength="16" minlength="6" name="payPwd" id="payPwd" type="text"
               style="color: rgb(0, 0, 0);">
      </li>
    </ul>
    <ul class="formUl">
      <li class="">
        <input class="inputBut showL inputBtnBig" type="button" value="确认" id="jax">
      </li>
    </ul>
  </form>
  <div class="height5"></div>
  <div class="tapList borderGray clearfix">
    <div class="tapTile">
      <h3 class="curr">最近提现</h3>
    </div>
    <div class="height5"></div>
    <div class="tableClassA clearfix">
      <table cellpadding="0" cellspacing="0">
        <thead>
        <tr>
          <th>订单流水</th>
          <th>积分类型</th>
          <th>提现积分</th>
          <th>复消积分</th>
          <th>管理费用</th>
          <th>公益积分</th>
          <th>久福币</th>
          <th>时间</th>
        </tr>
        </thead>
        <tbody>
        <tr class="noList showCss" ng-repeat="item in contents">
          <td>
            {{item.wrOrderno}}
          </td>
          <td>
            {{item.wrPointTypeStr}}
          </td>
          <td>
            {{item.wrPoint}}
          </td>
          <td>
            {{item.wrReusablePoint}}
          </td>
          <td>
            {{item.wrChargePoint}}
          </td>
          <td>
            {{item.wrWalfarePoint}}
          </td>
          <td>
            {{item.wrCurrencyPoint}}
          </td>
          <td>
            {{item.wrDate}}
          </td>
        </tr>
        </tbody>
      </table>
    </div>
    <div style="margin-left: 20px;">
      <div paging
           ul-class="pagination"
           page="currentPage"
           page-size="pageSize"
           total="total"
           show-prev-next="true"
           show-first-last="true"
           text-first="&laquo;"
           text-last="&raquo;"
           text-next="&rsaquo;"
           text-prev="&lsaquo;"
           text-title-page="第{page}页"
           text-title-first="首页"
           text-title-last="尾页"
           text-title-next="下一页"
           text-title-prev="上一页"
           paging-action="pageAction('Action', page,pageSize,total)">
      </div>
    </div>
  </div>
</div>
<script type="text/javascript">

  $(function () {

    $("*[name='payPwd']").focus(function () {
      $(this).attr('type', 'password');
    })
  })

  function buy() {
    $('body').mLoading('show');
    var address = $('#to').val();
    if (!address || address <= 0) {
      $('body').mLoading('hide');

      error('请先选择一个交易平台', function () {

      })
      return false;
    }

    var style = $('#pointType').val();
    var pointType = 0;
    if (style == 'original')
      pointType = 4;
    else if (style == 'repeat')
      pointType = 5;
    else if (style == 'static')
      pointType = 10;
    else if (style == 'dynamic')
      pointType = 11;

    $.post('/transaction/withdraw', {
      payPwd: $.md5($('#payPwd').val()),
      pointType: pointType,
      withdrawPoint: $('#pointAmount').val(),
      addressType: address,
      coinPrice: $('#coinPrice').text()
    }, function (data) {
      if (data.retCode == 1) {
        $('body').mLoading('hide');
        success(data.retMsg, function () {
          location.reload();
        })
      } else {

        $('body').mLoading('hide');
        error(data.retMsg, function () {

        })
      }
    })
  }

  $('#jax').bind('click', buy);

  function tipsTop(obj) {
    var style = $(obj).val();
    if (style == 'original') {
      $('.tipsTop').html('原始积分80%提现，15%作为复消积分，5%进入公益基金。');
      $('#errorMessage').html('(提取积分-复消积分-公益积分)/当前久福币价格');
    }
    if (style == 'repeat') {
      $('.tipsTop').html('复投积分80%提现，15%作为复消积分，5%进入公益基金。');
      $('#errorMessage').html('(提取积分-复消积分-公益积分)/当前久福币价格');
    }
    if (style == 'static') {
      $('.tipsTop').html('静态积分满100元起提，按100元的倍数，70%提现，20%作为复消积分，5%进入公益基金，5%作为提现手续费。');
      $('#errorMessage').html('(提取积分-管理费-公益积分-复消积分)/当前久福币价格');
    }
    if (style == 'dynamic') {
      $('.tipsTop').html('动态积分500元起提，100的倍数，70%可提现，提取收取20%积分作为复消积分，5%积分管理费，5%公益积分。');
      $('#errorMessage').html('(提取积分-管理费-公益积分-复消积分)/当前久福币价格');
    }
    $('#money').val('');
    $('#score').val('');
  }

  function calculatePoint() {

    $('#coinAmount').val('正在计算...');
    var style = $('#pointType').val();
    var withdrawPointType = 0;
    if (style == 'original')
      withdrawPointType = 4;
    else if (style == 'repeat')
      withdrawPointType = 5;
    else if (style == 'static')
      withdrawPointType = 10;
    else if (style == 'dynamic')
      withdrawPointType = 11;

    $.post('/transaction/calculateWithdrawPoint', {

      pointAmount: $('#pointAmount').val(),
      pointType: withdrawPointType,
      coinPrice: $('#coinPrice').text()
    }, function (data) {
      $('#coinAmount').val(data.data.coinAmount);
    })
  };

  function checkAddress(obj) {
    $('#errorAdd').html(' ');
    var address = $(obj).val();
    //$.post('/transaction/check-address', {address: address}, function (data) {
    //$('#errorAdd').html(data.msg);
    //})
  }

  function getPoint() {
    $.post('/transaction/getPoint', {}, function (data) {
      if (data.retCode == 1) {
        $('option[value=original]').html("原始积分(" + data.data.cpOriginalPoint + ")");
//        $('option[value=repeat]').html("复投积分(" + data.data.cpRepeatPoint + ")");
        $('option[value=static]').html("静态积分(" + data.data.cpAvailableStaticPoint + ")");
        $('option[value=dynamic]').html("动态积分(" + data.data.cpDynamicPoint + ")");
      } else {

      }
    })
  };

  getPoint();

  function getUser() {
    $.post('/user/currentUser', {}, function (data) {
      if (data.retCode == 1) {
        $('#username').val(data.data.userName);
      } else {

      }
    })
  }

  getUser();

  function getTypes() {
    $.post('/transaction/getAddrs', {}, function (data) {
      if (data.retCode == 1) {
        var selOpt = $("#to option");
        selOpt.remove();
        $("#to").append("<option value=\"0\">选择一个交易平台</option>");
        for (var i = 0; i < data.dataList.length; i++) {
          var opt = "<option value='" + data.dataList[i].wrType + "'>" + data.dataList[i].wrType + "</option>";
          //console.log(opt);
          $("#to").append(opt);
        }
      } else {

      }
    })
  }

  getTypes();

  function getCoinPrice() {

    $.post('/wallet/coinprice', {}, function (result) {
      if (result.retCode == 1) {
        $('#coinPrice').text(result.data.currentPrice);
      }
    })
  };

  getCoinPrice();

</script>
